<template>
  <!-- 绑定社区的页面 -->
  <view class="container">
    <!-- 头部提示区域 -->
    <view class="top">
      用户社区绑定
    </view>
    <!-- 头像区域 -->
    <view class="avatar">
      <text>头像</text>
      <u-avatar :src="userInfo.avatarUrl" size="50"></u-avatar>
    </view>
    <view class="nickname">
      <text>昵称</text>
      <text>{{userInfo.nickName}}</text>
    </view>
    <u--form labelPosition="left" :model="communityInfo" :rules="communityRules" ref="communityRef" labelWidth="80">
      <u-form-item label="用户电话:" prop="phone" borderBottom>
        <u--input v-model="communityInfo.phone" border="none" placeholder="请填写电话号码" suffixIcon="phone-fill"></u--input>
      </u-form-item>
      <u-form-item label="所在地区:" prop="region"  borderBottom >
          <u--input v-model="communityInfo.region" border="none" placeholder="请填写所在地区" suffixIcon="map-fill"></u--input>
      </u-form-item>
      <u-form-item label="详细地址:" prop="address" borderBottom>
        <u--input v-model="communityInfo.address" border="none" placeholder="请填写详细地址" suffixIcon="map-fill"></u--input>
      </u-form-item>
      <u-form-item borderBottom>
        <view class="default-community">
          <span>是否设置为默认社区</span>
          <u-switch v-model="communityInfo.value" activeColor="#7cb717"></u-switch>
        </view>
      </u-form-item>
    </u--form>
    <view class="submit" @click="submitForm"> 
      提交审核
    </view>

  </view>
</template>

<script>
  import {
    mapState
  } from 'vuex'
  export default {
    name: "BindCommunity",
    data() {
      return {
        // 用户的头像img
        avatarImg: '',
        // 用户的绑定信息
        communityInfo: {
          value:false
        },
        communityRules: {
         phone: {
          					type: 'string',
          					required: true,
          					message: '请填写电话号码',
          					trigger: ['blur', 'change']
          				},
          region:{
            type: 'string',
            required: true,
            message: '请填写所在地区',
            trigger: ['blur', 'change']
          },
          address:{
            type: 'string',
            required: true,
            message: '请填写详细地址',
            trigger: ['blur', 'change']
          }
        }
      };
    },
    computed: {
      ...mapState('m_user', ['userInfo'])
    },
    methods: {
      // 提交审核表单
    submitForm() {
    			this.$refs.communityRef.validate().then(res => {
    				uni.$u.toast('校验通过')
    			}).catch(errors => {
    				uni.$u.toast('校验失败')
    			})
    		},
    },
  }
</script>

<style lang="scss">
  page {
    background-color: aliceblue;
  }

  .container {
    padding: 10px;
  }

  .top {
    border-bottom: 1px solid #eee;
    padding: 10px;
  }

  .avatar {
    height: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    font-weight: 800;
  }

  .nickname {
    display: flex;
    justify-content: space-between;
    height: 44px;
    border-bottom: 1px solid #eee;
    align-items: center;
    margin-bottom: 10px;
  }
  .default-community{
    display: flex;
    justify-content: space-between;
  }
  .submit{
    margin-top: 20px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    background-color: #7cb717;
  }
</style>
